package item.inkcloud.userservice.service;

import item.inkcloud.userservice.entity.UserInfo;
import item.inkcloud.userservice.mapper.UserMapper;
import item.inkcloud.userservice.feignService.DistributionService;
import item.inkcloud.userservice.pojo.ProvinceHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegistUserService {

    @Autowired
    DistributionService distributionService;

    @Autowired
    UserMapper userMapper;

    @Autowired
    ProvinceHandler provinceHandler;

    public int registUser(UserInfo info){

            String province = info.getProvince();
           String newProvince = provinceHandler.handleProvince(province);

           info.setProvince(newProvince);

            try {
                userMapper.userRegister(info);
                int status = distributionService.addCount(info.getProvince());
                return status;
            }catch (Exception e){
                System.out.println(e.getCause());
                return 0;
            }

    }

}
